﻿using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Utilities;
using Srs.Sample.UI.CustomerService;

namespace Srs.Sample.UI.WebParts
{

    public class SrsAjaxWebPart : WebPart
    {
        private Label _displayName;
        private TextBox _inputName;

        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            this.EnsurePanelFix();
            UpdatePanel updatePanel = new UpdatePanel();

            Button sayHello = new Button();

            _displayName = new Label();
            _inputName = new TextBox();

            _displayName.ID = "displayName";
            _displayName.Text = "Hello!";

            _inputName.ID = "inputName";

            sayHello.ID = "sayHello";
            sayHello.Text = "Say Hello";

            updatePanel.ID = "updatePanel";
            updatePanel.UpdateMode = UpdatePanelUpdateMode.Conditional;
            updatePanel.ChildrenAsTriggers = true;

            sayHello.Click += new EventHandler(sayHello_Click);

            updatePanel.ContentTemplateContainer.Controls.Add(_inputName);
            updatePanel.AddLineBreak();
            updatePanel.ContentTemplateContainer.Controls.Add(_displayName);
            updatePanel.AddLineBreak();
            updatePanel.ContentTemplateContainer.Controls.Add(sayHello);

            this.Controls.Add(this.GetScriptManager());
            this.Controls.Add(updatePanel);


        }

        void sayHello_Click(object sender, EventArgs e)
        {
            _displayName.Text = "Hello " + _inputName.Text.ToString();
        }


    }
}
